#include <stdio.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrArith.h>
#include <flgrCoreCopy.h>
#include <flgrMorphoGeodesy.h>
#include "../macro.h"

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGeo_Dilate(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105,114, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 77, 75, 77, 77, 76,		\
		  75, 78, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,122,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,101, 99,		\
		  97, 96, 99,101, 98, 93, 99, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *imgmark, *img, *nhb;			\
  FLGR_Ret ret;								\
  									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgmark = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_RECT, FLGR_8_CONNEX);		\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  									\
  flgr2d_arith_const_sub_str(imgmark,imgsrc,"1");			\
									\
  ret=flgr2d_geodesic_dilate(img,imgmark,imgsrc,nhb);			\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imgmark);						\
  flgr2d_destroy(nhb);							\
  flgr2d_destroy(img);							\
									\
  return 1

int testgeo_dilate_fgUINT8(void) {
  tstGeo_Dilate(fgUINT8);
}
int testgeo_dilate_fgUINT16(void) {
  tstGeo_Dilate(fgUINT16);
}
int testgeo_dilate_fgUINT32(void) {
  tstGeo_Dilate(fgUINT32);
}
int testgeo_dilate_fgINT8(void) {
  tstGeo_Dilate(fgINT8);
}
int testgeo_dilate_fgINT16(void) {
  tstGeo_Dilate(fgINT16);
}
int testgeo_dilate_fgINT32(void) {
  tstGeo_Dilate(fgINT32);
}
int testgeo_dilate_fgFLOAT32(void) {
  tstGeo_Dilate(fgFLOAT32);
}
int testgeo_dilate_fgFLOAT64(void) {
  tstGeo_Dilate(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGeo_Erode(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105,115, 29, 41, 42, 48, 54, 57, 62, 70,		\
		  73, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 56,		\
		  50, 44, 42, 33,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 88, 88, 88, 86, 87, 35,  6 };		\
									\
  FLGR_Data2D *imgsrc, *imgref, *imgmark, *img, *nhb;			\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgmark = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_RECT, FLGR_8_CONNEX);		\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  flgr2d_arith_const_add_str(imgmark,imgsrc,"1");			\
									\
  ret=flgr2d_geodesic_erode(img,imgmark,imgsrc,nhb);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imgmark);						\
  flgr2d_destroy(nhb);							\
  flgr2d_destroy(img);							\
									\
  return 1

int testgeo_erode_fgUINT8(void) {
  tstGeo_Erode(fgUINT8);
}
int testgeo_erode_fgUINT16(void) {
  tstGeo_Erode(fgUINT16);
}
int testgeo_erode_fgUINT32(void) {
  tstGeo_Erode(fgUINT32);
}
int testgeo_erode_fgINT8(void) {
  tstGeo_Erode(fgINT8);
}
int testgeo_erode_fgINT16(void) {
  tstGeo_Erode(fgINT16);
}
int testgeo_erode_fgINT32(void) {
  tstGeo_Erode(fgINT32);
}
int testgeo_erode_fgFLOAT32(void) {
  tstGeo_Erode(fgFLOAT32);
}
int testgeo_erode_fgFLOAT64(void) {
  tstGeo_Erode(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Dilate(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105, 112,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  76,  75,  76,  76,  77,  75,  75,  75,  75,	\
		  75,  76,  76,  76,  77,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32, 120, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96,  99,  96,  98,  98,  97,  99,  99,	\
		  96,  96,  99,  99,  98,  93,  99,  99,  94,  96,	\
		  94,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *imgmark;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgmark = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  flgr2d_arith_const_sub_str(imgmark,imgsrc,"3");			\
  									\
  ret=flgr2d_geodesic_reconstruct_dilate(imgmark,imgsrc,			\
				       FLGR_6_CONNEX);			\
  check_and_display_data2d(imgref,imgmark,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imgmark);						\
									\
  return 1

int testgeorec_dilate_fgUINT8(void) {
  tstGeorec_Dilate(fgUINT8);
}
int testgeorec_dilate_fgUINT16(void) {
  tstGeorec_Dilate(fgUINT16);
}
int testgeorec_dilate_fgUINT32(void) {
  tstGeorec_Dilate(fgUINT32);
}
int testgeorec_dilate_fgINT8(void) {
  tstGeorec_Dilate(fgINT8);
}
int testgeorec_dilate_fgINT16(void) {
  tstGeorec_Dilate(fgINT16);
}
int testgeorec_dilate_fgINT32(void) {
  tstGeorec_Dilate(fgINT32);
}
int testgeorec_dilate_fgFLOAT32(void) {
  tstGeorec_Dilate(fgFLOAT32);
}
int testgeorec_dilate_fgFLOAT64(void) {
  tstGeorec_Dilate(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Erode(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,100,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105, 115,  38,  41,  41,  48,  54,  57,  62,  70,	\
		  75,  76,  75,  76,  76,  78,  75,  77,  78,  76,	\
		  75,  79,  77,  76,  77,  73,  71,  65,  65,  65,	\
		  50,  44,  42,  42, 100, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96, 100,  96,  98,  98,  97, 102,  99,	\
		  98,  96,  99, 102,  98,  93, 100,  99,  94,  96,	\
		  94,  90,  88,  88,  88,  88,  87,  87,  35,  15};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *imgmark;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgmark = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  flgr2d_arith_const_add_str(imgmark,imgsrc,"10");			\
  ret=flgr2d_geodesic_reconstruct_erode(imgmark,imgsrc,			\
				      FLGR_4_CONNEX);			\
  check_and_display_data2d(imgref,imgmark,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imgmark);						\
									\
  return 1

int testgeorec_erode_fgUINT8(void) {
  tstGeorec_Erode(fgUINT8);
}
int testgeorec_erode_fgUINT16(void) {
  tstGeorec_Erode(fgUINT16);
}
int testgeorec_erode_fgUINT32(void) {
  tstGeorec_Erode(fgUINT32);
}
int testgeorec_erode_fgINT8(void) {
  tstGeorec_Erode(fgINT8);
}
int testgeorec_erode_fgINT16(void) {
  tstGeorec_Erode(fgINT16);
}
int testgeorec_erode_fgINT32(void) {
  tstGeorec_Erode(fgINT32);
}
int testgeorec_erode_fgFLOAT32(void) {
  tstGeorec_Erode(fgFLOAT32);
}
int testgeorec_erode_fgFLOAT64(void) {
  tstGeorec_Erode(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Dual(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105, 112,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  76,  75,  76,  76,  77,  75,  75,  75,  75,	\
		  75,  76,  76,  76,  77,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32, 120, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96,  99,  96,  98,  98,  97,  99,  99,	\
		  96,  96,  99,  99,  98,  93,  99,  99,  94,  96,	\
		  94,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *imgmark;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgmark = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  flgr2d_arith_const_sub_str(imgmark,imgsrc,"3");			\
  									\
  ret=flgr2d_geodesic_reconstruct_dual(imgmark,imgsrc,			\
				     FLGR_6_CONNEX);			\
  check_and_display_data2d(imgref,imgmark,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imgmark);						\
									\
  return 1

int testgeorec_dual_fgUINT8(void) {
  tstGeorec_Dual(fgUINT8);
}
int testgeorec_dual_fgUINT16(void) {
  tstGeorec_Dual(fgUINT16);
}
int testgeorec_dual_fgUINT32(void) {
  tstGeorec_Dual(fgUINT32);
}
int testgeorec_dual_fgINT8(void) {
  tstGeorec_Dual(fgINT8);
}
int testgeorec_dual_fgINT16(void) {
  tstGeorec_Dual(fgINT16);
}
int testgeorec_dual_fgINT32(void) {
  tstGeorec_Dual(fgINT32);
}
int testgeorec_dual_fgFLOAT32(void) {
  tstGeorec_Dual(fgFLOAT32);
}
int testgeorec_dual_fgFLOAT64(void) {
  tstGeorec_Dual(fgFLOAT64);
}








/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Open(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,100,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 76,  76,  28,  41,  41,  48,  54,  57,  62,  70,	\
		   72,  76,  75,  76,  76,  77,  75,  75,  75,  75,	\
		   75,  76,  76,  76,  77,  73,  71,  64,  62,  55,	\
		   50,  44,  42,  32,  90,  90,  90,  88,  82,  73,	\
		   73,  76,  76,  81,  85,  86,  90,  90,  92,  92,	\
		   91,  92,  92,  92,  92,  92,  92,  92,  92,  92,	\
		   92,  92,  92,  92,  92,  92,  92,  92,  92,  92,	\
		   92,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb     = flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, \
				       FLGR_6_CONNEX);			\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_geodesic_reconstruct_open(img,imgsrc,nhb);			\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testgeorec_open_fgUINT8(void) {
  tstGeorec_Open(fgUINT8);
}
int testgeorec_open_fgUINT16(void) {
  tstGeorec_Open(fgUINT16);
}
int testgeorec_open_fgUINT32(void) {
  tstGeorec_Open(fgUINT32);
}
int testgeorec_open_fgINT8(void) {
  tstGeorec_Open(fgINT8);
}
int testgeorec_open_fgINT16(void) {
  tstGeorec_Open(fgINT16);
}
int testgeorec_open_fgINT32(void) {
  tstGeorec_Open(fgINT32);
}
int testgeorec_open_fgFLOAT32(void) {
  tstGeorec_Open(fgFLOAT32);
}
int testgeorec_open_fgFLOAT64(void) {
  tstGeorec_Open(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_close types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Close(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,100,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105, 115,  76,  76,  76,  76,  76,  76,  76,  76,	\
		  76,  76,  76,  76,  76,  78,  76,  77,  78,  76,	\
		  76,  79,  77,  76,  77,  76,  76,  76,  76,  76,	\
		  76,  76,  76,  76, 100, 112, 100,  88,  82,  76,	\
		  76,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96, 100,  96,  98,  98,  97, 102,  99,	\
		  98,  96,  99, 102,  98,  96, 100,  99,  96,  96,	\
		  96,  96,  96,  96,  96,  96,  96,  96,  96,  96};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb     = flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_RECT, \
				       FLGR_8_CONNEX);			\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_geodesic_reconstruct_close(img,imgsrc,nhb);			\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testgeorec_close_fgUINT8(void) {
  tstGeorec_Close(fgUINT8);
}
int testgeorec_close_fgUINT16(void) {
  tstGeorec_Close(fgUINT16);
}
int testgeorec_close_fgUINT32(void) {
  tstGeorec_Close(fgUINT32);
}
int testgeorec_close_fgINT8(void) {
  tstGeorec_Close(fgINT8);
}
int testgeorec_close_fgINT16(void) {
  tstGeorec_Close(fgINT16);
}
int testgeorec_close_fgINT32(void) {
  tstGeorec_Close(fgINT32);
}
int testgeorec_close_fgFLOAT32(void) {
  tstGeorec_Close(fgFLOAT32);
}
int testgeorec_close_fgFLOAT64(void) {
  tstGeorec_Close(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Open_Tophat(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,100,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 51,  61,   0,   0,   0,   0,   0,   3,   8,  16,	\
		   18,  22,  21,  22,  22,  24,  21,  23,  24,  22,	\
		   21,  25,  23,  22,  23,  19,  17,  10,   8,   1,	\
		   0,   0,   0,   0,  46,  58,  46,  34,  28,  19,	\
		   19,  22,  22,  27,  31,  32,  36,  36,  39,  38,	\
		   37,  42,  42,  46,  42,  44,  44,  43,  48,  45,	\
		   44,  42,  45,  48,  44,  39,  46,  45,  40,  42,	\
		   40,  36,  34,  33,  34,  34,  31,  33,   0,   0};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(9,9,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_HEX,FLGR_6_CONNEX);		\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_geodesic_reconstruct_open_tophat(img,imgsrc,nhb);		\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
  									\
  return 1

int testgeorec_open_tophat_fgUINT8(void) {
  tstGeorec_Open_Tophat(fgUINT8);
}
int testgeorec_open_tophat_fgUINT16(void) {
  tstGeorec_Open_Tophat(fgUINT16);
}
int testgeorec_open_tophat_fgUINT32(void) {
  tstGeorec_Open_Tophat(fgUINT32);
}
int testgeorec_open_tophat_fgINT8(void) {
  tstGeorec_Open_Tophat(fgINT8);
}
int testgeorec_open_tophat_fgINT16(void) {
  tstGeorec_Open_Tophat(fgINT16);
}
int testgeorec_open_tophat_fgINT32(void) {
  tstGeorec_Open_Tophat(fgINT32);
}
int testgeorec_open_tophat_fgFLOAT32(void) {
  tstGeorec_Open_Tophat(fgFLOAT32);
}
int testgeorec_open_tophat_fgFLOAT64(void) {
  tstGeorec_Open_Tophat(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstGeorec_Close_Tophat(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,100,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 0,   0,  62,  49,  49,  42,  36,  33,  28,  20,	\
		   18,  14,  15,  14,  14,  12,  15,  13,  12,  14,	\
		   15,  11,  13,  14,  13,  17,  19,  26,  28,  35,	\
		   40,  46,  48,  58,   0,   0,   0,   2,   8,  17,	\
		   17,  14,  14,   9,   5,   4,   0,   0,   0,   0,	\
		   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,	\
		   0,   0,   0,   0,   0,   3,   0,   0,   2,   0,	\
		   2,   6,   8,   9,   8,   8,  11,   9,  61,  91};	\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(9,9,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_CROSS, FLGR_4_CONNEX);		\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_geodesic_reconstruct_close_tophat(img,imgsrc,nhb);		\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
 									\
  return 1

int testgeorec_close_tophat_fgUINT8(void) {
  tstGeorec_Close_Tophat(fgUINT8);
}
int testgeorec_close_tophat_fgUINT16(void) {
  tstGeorec_Close_Tophat(fgUINT16);
}
int testgeorec_close_tophat_fgUINT32(void) {
  tstGeorec_Close_Tophat(fgUINT32);
}
int testgeorec_close_tophat_fgINT8(void) {
  tstGeorec_Close_Tophat(fgINT8);
}
int testgeorec_close_tophat_fgINT16(void) {
  tstGeorec_Close_Tophat(fgINT16);
}
int testgeorec_close_tophat_fgINT32(void) {
  tstGeorec_Close_Tophat(fgINT32);
}
int testgeorec_close_tophat_fgFLOAT32(void) {
  tstGeorec_Close_Tophat(fgFLOAT32);
}
int testgeorec_close_tophat_fgFLOAT64(void) {
  tstGeorec_Close_Tophat(fgFLOAT64);
}


